<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/StoresSystem' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item >查看库存</el-breadcrumb-item>
      <!-- <el-breadcrumb-item :to="{ path: '/StoresSystem/' }">上架商品</el-breadcrumb-item> -->
    </el-breadcrumb>



    <el-table height="400px" size="small" :data="studentsData.filter(data => !search.searchValue || 
    data[search.searchType].toLowerCase().includes(search.searchValue.toLowerCase()) )
    " style="width: 100%">
      <el-table-column label="商品编号" prop="_id" width="150%"></el-table-column>
      <el-table-column label="商品名字" prop="name"></el-table-column>
      <el-table-column label="商品价格" prop="price"></el-table-column>
      <el-table-column label="商品数量" prop="num"></el-table-column>
      <el-table-column label="商品门店" prop="shopsId"></el-table-column>
      <el-table-column label="商品图片">
        <template slot-scope="scope">
          <img class="studentsImage" :src="scope.row.imagePath" />
        </template>
      </el-table-column>
      <el-table-column label="商品是否上架" prop="state"></el-table-column>
      <el-table-column align="right" width="200%">
        <template slot="header" slot-scope="scope">
          <!-- <div class="f-left">
            <el-button size="mini" @click="addGoods(scope.row)" :visible.sync="dialogFormVisible">新增库存</el-button>
          </div>-->
          <div class="f-left">
            <el-select v-model="search.searchType" size="mini">
              <el-option label="商品名字" value="name"></el-option>
              <el-option label="商品价格" value="price"></el-option>
              <el-option label="商品数量" value="num"></el-option>
              <el-option label="所属门店" value="shopsId"></el-option>
            </el-select>
            <el-input v-model="search.searchValue" size="mini" placeholder="输入关键字搜索" />
          </div>
        </template>
        <template slot-scope="scope">
          <el-button size="mini" @click="updateStudents(scope.row)">修改</el-button>

          <el-dialog title="修改信息" :visible.sync="dialogFormVisible">
            <el-form :model="form">
              <el-form-item label="名字：">
                <el-input v-model="form.name" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="价格：">
                <el-input v-model="form.price" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="数量：">
                <el-input v-model="form.num" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="所属门店：">
                <el-input v-model="form.price" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="数量：">
                <el-radio v-model="form.state" label="unsold">已上架</el-radio>
                <el-radio v-model="form.state" label="sell">未上架</el-radio>
              </el-form-item>
              <!-- <el-form-item label="班级：">
                <el-select v-model="form.classesId._id" placeholder="修改班级">
                  <el-option
                    v-for="item in classesData"
                    :key="item._id"
                    :label="item.name"
                    :value="item._id"
                  ></el-option>
                </el-select>
              </el-form-item>-->
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="close">取 消</el-button>
              <el-button type="primary" @click="sure(form._id)">确 定</el-button>
            </div>
          </el-dialog>

          <el-button
            size="mini"
            type="danger"
            @click="getRemoveStudentAsync(scope.row._id)"
            :plain="true"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageData.currentPage"
        :page-sizes="[4,5,6,7]"
        :page-size="pageData.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageData.studentsTotal"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { createNamespacedHelpers } from "vuex";
const {
  mapState,
  mapGetters,
  mapMutations,
  mapActions
} = createNamespacedHelpers("stores");

export default {
  data() {
    return {
      search: {
        searchType: "",
        searchValue: ""
      }
    };
  },
  computed: {
    ...mapState([
      "studentsData",
      "classesData",
      "dialogFormVisible",
      "form",
      "pageData"
    ])
  },
  created() {
    this.getStudentsAsync();
    this.getClassesData();
    console.log(this.studentsData);
  },
  methods: {
    ...mapMutations(["updateStudents", "close"]),
    ...mapActions([
      "getStudentsAsync",
      "getRemoveStudentAsync",
      "getClassesData",
      "sure",
      "handleSizeChange",
      "handleCurrentChange",
      "addGoods"
    ]),
    // updateStudents(_id) {
    //   this.$router.push("/system/studentupdata" + _id);
    // },
  }
};
</script>

<style>
.el-breadcrumb {
  padding-left: 25px;
  height: 30px;
}


.has-gutter .el-table_1_column_7 .cell {
  width: 300px !important;
  width: 100% !important;
  display: flex !important;
}
.has-gutter .el-table_1_column_7 .cell .f-left:first-child {
  margin-right: 10px !important;
}
.has-gutter .el-table_1_column_7 .cell .f-left {
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
}
.has-gutter .el-table_1_column_7 .cell .f-left .el-select {
  width: 150px !important;
}
.has-gutter .el-table_1_column_7 .cell .f-left .el-input {
  width: 150px !important;
}

.el-table__header-wrapper .has-gutter tr th {
  line-height: 60px;
}
.has-gutter .cell {
  text-align: center;
  font-size: 14px;
}
.el-table__row .cell {
  text-align: center;
}
.is-right button {
  margin-right: 5px;
}
.el-dialog {
  width: 440px;
}
.el-form-item {
  padding: 0 40px;
}
.el-dialog__header {
  display: flex;
}
.el-dialog .el-input {
  width: 260px;
}
.el-dialog__close {
  display: none;
}
.dialog-footer {
  padding-right: 40px;
}

.el-pagination {
  margin-top: 10px;
  height: 30px !important;
}
.studentsImage {
  width: 50px;
}
</style>